﻿using QuanLyBanHang.BLL;
using QuanLyBanHang.DAL;
using QuanLyBanHang.DoiTuongLayThongTin;
using QuanLyBanHang.DTO;
using QuanLyBanHang.QLLayThongTin;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace QuanLyBanHang
{
    public partial class frmHoaDon : Form
    {
        HoaDonDTO hd = new HoaDonDTO();
        HoaDonDAL hdDal = new HoaDonDAL();
        public frmHoaDon()
        {
            InitializeComponent();
        }
        //kiem tra thong tin hoa don 
        

        private void frmHoaDon_Load(object sender, EventArgs e)
        {
            //this.Show();
            dataGridView1.DataSource= HoaDonBLL.LayTatCaThongTinHoaDon(hd);
        }
        //dau tat ca du lieu len datagridview
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            int i = e.RowIndex;
            textBox1.Text = dataGridView1.Rows[i].Cells["MaHD"].Value.ToString();
            textBox2.Text = dataGridView1.Rows[i].Cells["MaKH"].Value.ToString();
            textBox4.Text = dataGridView1.Rows[i].Cells["MaNV"].Value.ToString();
            dateTimePicker1.Text = dataGridView1.Rows[i].Cells["NgayLapHD"].Value.ToString();

        }

        private void button1_Click(object sender, EventArgs e)
        {
            HoaDonDTO.MaHD = textBox1.Text;
            HoaDonDTO.MaKH = textBox2.Text;
           
            TTHoaDon ttHD = new TTHoaDon();
            if (textBox1.Text == "") MessageBox.Show("chua nhap ma hoa don");
            else if (textBox2.Text == "") MessageBox.Show("chua nhap ma khach hang");
            else if (ttHD.KiemTraTTHoaDon(hd))
            {
                //  string kq = DaBLL.QuyenDN(Dn).ToString();
                //MessageBox.Show("dang nhap thanh cong:" + UserInfo.UserNane);
                //MessageBox.Show("Xinh Chao :" + UserInfo.UserNane);

                this.Hide();
                frmChiTietHoaDon f = new frmChiTietHoaDon();
                //f.Message1 = comboBox1.Text;//truyen du lieu về form 2
                //f.Quyen = DaBLL.QuyenDN(Dn);//xuất ra quyền của người đăng nhập
                f.ShowDialog();


            }
            else
            {
                MessageBox.Show("dang nhap khong thanh cong:");
                textBox1.ResetText();
            }
            

        }
        
    }
}
